<template>
    <div class="news-wrapper">
        <div class="left" data-200-center-top="transform: translateX(-150%); opacity: 0"
            data-50-center-center="transform: translateX(0); opacity: 1">
            <el-carousel arrow="always" class="carousel" indicator-position="outside" height="380px" :autoplay="isAutoplay">
                <el-carousel-item v-for="(item, index) in rotationList" :key="index">
                    <el-image :src="item.address" fit="cover" v-if="item.type == 0">
                        <template #error>
                            <div class="image-slot">
                                <el-icon><icon-picture /></el-icon>
                            </div>
                        </template>
                    </el-image>
                    <video autoplay loop controls :src="videoSrc" v-if="item.type == 1" @mouseenter="getVedio(item.id)"
                        @mouseleave="setAutoplay">
                    </video>
                </el-carousel-item>
            </el-carousel>
        </div>
        <div class="right" data-200-center-top="transform: translateX(150%); opacity: 0"
            data-50-center-center="transform: translateX(0); opacity: 1">
            <el-timeline>
                <el-timeline-item :timestamp="new Date(item.timestamp).toLocaleDateString()" placement="top"
                    v-for="(item, index) in timeLineList" :key="index">
                    <el-card>
                        <h4>{{ item.content }}</h4>
                    </el-card>
                </el-timeline-item>
            </el-timeline>
        </div>
    </div>
</template>

<script setup>
import { Picture as IconPicture } from '@element-plus/icons-vue'
import { listNews, listRotation, listRotationVedio } from '../api/info'

let isAutoplay = ref(true)

let timeLineList = ref([])
let rotationList = ref([])
listNews().then(res => {
    timeLineList.value = res.rows
})
listRotation().then(res => {
    rotationList.value = res.rows
})

let videoSrc = ref('')
const getVedio = (item_id) => {
    listRotationVedio({
        id: item_id
    }).then(res => {
        videoSrc.value = `http://${res.msg}`
        isAutoplay.value = false
    })
}
const setAutoplay = () => {
    isAutoplay.value = true
}
</script>

<style scoped>
.news-wrapper {
    padding: 40px 80px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    flex-wrap: wrap;
}

video {
    width: 100%;
    object-fit: cover;
}

.left {
    width: 700px;
    margin-bottom: 20px;
}

.right {
    width: 700px;
    text-align: left;
}

.el-carousel__item::before {
    /* // 幽灵空白节点，借助一个虚无的前节点实现垂直方向上的居中 */
    content: '';
    display: inline-block;
    height: 100%;
    vertical-align: middle;
}

.image-slot {
    vertical-align: middle;
    font-size: 50px;
}

.el-carousel__item h3 {
    color: #475669;
    opacity: 0.75;
    line-height: 300px;
    margin: 0;
    text-align: center;
}
</style>